package com.dtu.distributed.thread;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

import com.dtu.distributed.controller.BullyAlgorithmControlller;
import com.dtu.distributed.controller.TempController;
import com.dtu.distributed.enums.Action;

public class AdminElectionListenerThread extends Thread {
	
	private boolean runThread = true;
	private ServerSocket serverSocket;
	private Socket clientSocket;

		
	@Override
	public void run() {
		System.out.println("tcp listener is running..");
		try {
			serverSocket = new ServerSocket(TempController.electionPort);
			//while (!this.isInterrupted()) {does not seem to work
			while (runThread) {
				clientSocket = serverSocket.accept();
				AdminElectionThread adminThread = new AdminElectionThread(
						clientSocket);
			}
			serverSocket.close();
			
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Stopped");
		}

	}

}
